{extend name="platform/base" /}
{block name="main"}
<div class="row padder-v">
    <div class="col-sm-7">
    </div>


    <div class="col-sm-2">
        <div class="input-group">
            <input type="text" id="search_text" style="display:inline" class="input-sm form-control" placeholder="请输入亲友卡名称">
            <select name="" id="search_select" class="input-sm form-control" >
                <option value="">选择状态</option>
                <option value="1">开启</option>
                <option value="0">关闭</option>
            </select>

        </div>
    </div>
    <div class="col-sm-1">
        <div class="input-group">
                    <span class="input-group-btn">
                    <button class="btn btn-sm btn-default" type="button" onclick="LoadingInfo(1)">搜索</button>
                    </span>
        </div>
    </div>

</div>
<section class="panel panel-default">
    <div class="table-responsive">
        <table  class="table table-striped b-light text-sm">
            <colgroup>
                <col width="3%">
                <col width="7%">
                <col width="7%">
                <col width="10%">
                <!-- <col width="15%"> -->
                <col width="15%">
                <col width="7%">
                <col width="7%">
                <col width="10%">
                <col width="10%">
                <col width="9%">
                <col width="5%">

            </colgroup>
            <thead>
            <tr>
                <th class="center"><input type="checkbox"></th>
                <th>主题名称</th>
                <th>亲友卡名称</th>
                <th class="left">亲友卡售价</th>
                <th class="left">亲友卡次数</th>
                <!-- <th class="center">点击量/评论量</th> -->
                <th class="left">启用状态</th>
                <th class="left">卡片类型</th>
                <th class="left">背景图片</th>
                <th class="left">申请时间</th>
                <th class="left" >创建时间</th>

                <th class="left">状态</th>
                <th class="left">操作</th>

            </tr>
            <tbody id="list">
            <tr></tr>
            </tbody>
        </table>
    </div>
    {include file="platform/page" /}
</section>
{/block}
{block name="script"}
<script type="text/javascript">
    $(function(){
        LoadingInfo(1);
    });
    //分页数据
    function LoadingInfo(pageIndex) {
        var search_text = $("#search_text").val();
        var status = $("#search_select").val();
        $.ajax({
            type : "post",
            url : "{:__URL('PLATFORM_MAIN/FamilyCard/index')}",
            async : true,
            data : {
                'name' : search_text,
                'status':status
            },
            success : function(data) {
                var html = '';
                $("#total_count_num").text(data["total_count"]);
                $("#page_count_num").text(data["page_count"]);
                $("#page_count").val(data["page_count"]);
                var image_url = "";
                $("#pageNumber a").remove();
                console.log(data)
                if (data["data"].length > 0) {
                    for (var i = 0; i < data["data"].length; i++) {
                        image_url = data["data"][i]["background"];
                        html += '<tr>';
                        html += '<td class="left">' +data["data"][i]["id"]+ '</td>';
                        html += '<td title="'+data["data"][i]["theme"]+'">' + data["data"][i]["theme"]+ '</td>';
                        html += '<td title="'+data["data"][i]["name"]+'">' + data["data"][i]["name"]+ '</td>';
                        html += '<td title="'+data["data"][i]["name"]+'">' + data["data"][i]["price"]+ '</td>';
                        html += '<td class="left">' + data["data"][i]["frequency"]+ '</td>';
                        // html += '<td class="center">' + data["data"][i]["click"]+ ' / ' + data["data"][i]["comment_count"]+ '</td>';
                        // html += '<td><input type="number" value="'+ data["data"][i]["desc"]+'"  fieldid="'+ data['data'][i]['desc']+'" class="num form-control" ></td>';
                        if(data["data"][i]["is_status"]==0){
                            html += '<td class="left" value ="'+data["data"][i]["is_status"]+'" id ="status-'+data["data"][i]["id"]+'" ><b style="color: grey;">关闭</b></td>';
                        }else if(data["data"][i]["is_status"]==1){
                            html += '<td class="left"  value ="'+data["data"][i]["is_status"]+'"id ="status-'+data["data"][i]["id"]+'" ><b style="color: blue;">开启</b></td>';
                        }
                        if(data["data"][i]["is_classic"]==1){
                            html += '<td class="left" value ="'+data["data"][i]["is_classic"]+'" id ="status-'+data["data"][i]["id"]+'" ><b style="color: grey;">经典</b></td>';
                        }else if(data["data"][i]["is_classic"]==2){
                            html += '<td class="left"  value ="'+data["data"][i]["is_classic"]+'"id ="status-'+data["data"][i]["id"]+'" ><b style="color: blue;">精选</b></td>';
                        }

                        html += '<td class="left"><img src="'+image_url+'" class="lazy_load" data-original="'+__IMG(data["data"][i]["background"])+'" /></td>';
                        html += '<td class="left">' + timeStampTurnTime(data["data"][i]["created_at"])+ '</td>';
                        html += '<td class="left">' + timeStampTurnTime(data["data"][i]["updated_at"])+ '</td>';

                        if(data["data"][i]["status"]==0){
                            html += '<td class="left" value ="'+data["data"][i]["status"]+'" id ="status-'+data["data"][i]["id"]+'" ><b style="color: grey;">审核中</b></td>';
                        }else if(data["data"][i]["status"]==1){
                            html += '<td class="left"  value ="'+data["data"][i]["status"]+'"id ="status-'+data["data"][i]["id"]+'" ><b style="color: green;">审核确认</b></td>';
                        }else if(data["data"][i]["status"]==2){
                            html += '<td class="left" value ="'+data["data"][i]["status"]+'" id ="status-'+data["data"][i]["id"]+'" ><b style="color: green"> 完成审核</b></td>';
                        }else if(data["data"][i]["status"]==-1){
                            html += '<td class="left"  value ="'+data["data"][i]["status"]+'" id ="status-'+data["data"][i]["id"]+'" ><b style="color: red"> 拒绝</b></td>';
                        }

                        html += '<td class="center"><button class="btn btn-sm btn-default"  type="button" onclick="getSettled(' + data['data'][i]['id'] + ')">查看详情</button></td>';
                        html += '<td class="center"><button class="btn btn-sm btn-default"  type="button" onclick="editSettled(' + data['data'][i]['id'] + ')">编辑</button></td>';

                        html += '</tr>';
                    }
                } else {
                    html += '<tr align="center"><td colspan="9">暂无文章数据记录</td></tr>';
                }
                $("#list").html(html);
                var totalpage = $("#page_count").val();
                if (totalpage == 1) {
                    changeClass("all");
                }
                var $html = pagenumShow(jumpNumber,totalpage,{$pageshow})
                $("#pageNumber").append($html);
                load();
            }
        });
    }

    //删除分类
    function deleteArticle(article_id){
        $( "#dialog" ).dialog({
            buttons: {
                "确定": function() {
                    $(this).dialog('close');
                    $.ajax({
                        type : "post",
                        url : "{:__URL('PLATFORM_MAIN/Cms/deleteArticle')}",
                        async : true,
                        data : {
                            "article_id" : article_id
                        },
                        success : function(data) {
                            //alert(JSON.stringify(data));
                            if (data["code"] > 0) {
                                showMessage('success', data["message"]);
                                LoadingInfo(1);
                            }else{
                                showMessage('error', data["message"]);
                            }
                        }
                    })
                },
                "取消,#e57373": function() {
                    $(this).dialog('close');
                }
            },
            contentText:"是否删除文章？",
        });
    }
    /*修改排序*/
    function load(){
        $('.num').change(function(){
            var fieldid = $(this).attr('fieldid');
            var sort = $(this).val();
            //alert(sort);
            $.ajax({
                type:"post",
                url:"{:__URL('PLATFORM_MAIN/Cms/modifyArticleField')}",
                data:{'fieldid':fieldid,'sort':sort},
                async:true,
                success: function (data) {
                    if (data["code"] > 0) {
                        showMessage('success', data["message"]);
                        LoadingInfo(1);
                    }else{
                        showMessage('error', data["message"]);
                    }
                }
            });
        });
    }



    function  getSettled(index) {
        window.location.href = "{:__URL('PLATFORM_MAIN/FamilyCard/view?id=')}"+index;
    }

    function  editSettled(index) {
        window.location.href = "{:__URL('PLATFORM_MAIN/FamilyCard/editFamilyCard?id=')}"+index;
    }

</script>
{/block}